

/*
additional long-difference regressions of asset prices on auction shocks

output:
- f2e_longdiff_coeffs.pdf: coeffs across difference forward steps

*/


* plotting options
set scheme lean_uncluttered


********************************************************************************
********************************************************************************

n di "10-year Treasury rates"

* size and maximum forward step
local max_h_step 60
local h_step 1


* 10y spot rate from fred
use date DGS10 using ../data/fred/_fred_treasury_rates.dta, clear
drop if DGS10==.
sort date
forvalues h=0(`h_step')`max_h_step' {
	* long-difference relative to day before auction
	* re-scale to basis points
	gen long`h'_D_DGS10 = 100*(DGS10[_n+`h'] - DGS10[_n-1])
}
tempfile londiff
save `londiff', replace

* merge with auction date
use ../data/auction_notesbonds_govpx_shock.dta, clear
rename auctionDate date
* note: for daily data, only keep later auction if multiple occur in one day
* only a handful of multiple auctions
bys date (close_time): gen _idx_keep = _n==_N
keep if _idx_keep
drop _idx_keep
* merge
merge 1:1 date using `londiff', nogen keep(match)

* for newey-west SEs
sort release_time
gen _T = _n
tsset _T

* run long-diff regressions
matrix results = J(`=1+`max_h_step'',6, .)
forvalues h=0(`h_step')`max_h_step' {
	local idx = `h' + 1
	ivreg2 long`h'_D_DGS10 D_shock, r bw(9)
	* save coeff and 1- and 2-se bands
	mat results[`idx',1] = _b[D_shock]
	mat results[`idx',2] = _b[D_shock] - _se[D_shock]
	mat results[`idx',3] = _b[D_shock] + _se[D_shock]
	mat results[`idx',4] = _b[D_shock] - 2*_se[D_shock]
	mat results[`idx',5] = _b[D_shock] + 2*_se[D_shock]
	mat results[`idx',6] = `h'
}

* combine with normalized changes in yields following QE1
use date DGS10 using ../data/fred/_fred_treasury_rates.dta, clear
drop if DGS10==.
sort date
forvalues h=0(`h_step')`max_h_step' {
	* long-difference relative to day before auction
	* normalize so 1-day change is 1
	gen long`h'_D_DGS10 = (DGS10[_n+`h'] - DGS10[_n-1]) / (DGS10[_n] - DGS10[_n-1])
}
drop DGS10
* QE1 final announcement
keep if date==mdy(3,18,2009)
reshape long long@_D_DGS10, i(date) j(h)
drop date
rename long_D_DGS10 qe1_normalized_ylds
tempfile qe1_normalized_ylds
save `qe1_normalized_ylds', replace

***************************
* plot
clear
svmat results
rename results1 b
rename results2 ci_l1
rename results3 ci_u1
rename results4 ci_l2
rename results5 ci_u2
rename results6 h

* combine with QE1 respones
merge 1:1 h using `qe1_normalized_ylds', nogen

* plot
twoway (rarea ci_l1 ci_u1 h , color(gs12) ) ///
	(line b ci_l2 ci_u2 h, lcolor("scheme p1" "scheme p1" "scheme p1") ///
		lpattern(solid shortdash shortdash ) lwidth(medium thin thin)) ///
	(line qe1_normalized_ylds h, lcolor("scheme p2") ///
		lpattern(longdash ) lwidth(thick)), ///
	xtitle("Days") ytitle("D{sub:t} Coeff.") ///
	legend(order(2 "Coefficient" 5 "Normalized QE Resp.") ring(0) position(7)) ///
	title("Panel A: 10-Year Treasury Yields") ///
	name(longdiff_t10, replace) nodraw

***************************
n di "Moody's Aaa rates"
use date DAAA using ../data/fred/_fred_raw.dta, clear
rename DAAA MD_AAA
drop if missing(MD_AAA)
sort date
forvalues h=0(`h_step')`max_h_step' {
	* long-difference relative to day before auction
	* re-scale to basis points
	gen long`h'_D_MD_AAA = 100*(MD_AAA[_n+`h'] - MD_AAA[_n-1])
}
tempfile londiff
save `londiff', replace

* merge with auction date
use ../data/auction_notesbonds_govpx_shock.dta, clear
rename auctionDate date
* note: for daily data, only keep later auction if multiple occur in one day
* only a handful of multiple auctions
bys date (close_time): gen _idx_keep = _n==_N
keep if _idx_keep
drop _idx_keep
* merge
merge 1:1 date using `londiff', nogen keep(match)

* for newey-west SEs
sort release_time
gen _T = _n
tsset _T

* run long-diff regressions
matrix results = J(`=1+`max_h_step'',6, .)
forvalues h=0(`h_step')`max_h_step' {
	local idx = `h' + 1
	ivreg2 long`h'_D_MD_AAA D_shock, r bw(9)
	* save coeff and 1- and 2-se bands
	mat results[`idx',1] = _b[D_shock]
	mat results[`idx',2] = _b[D_shock] - _se[D_shock]
	mat results[`idx',3] = _b[D_shock] + _se[D_shock]
	mat results[`idx',4] = _b[D_shock] - 2*_se[D_shock]
	mat results[`idx',5] = _b[D_shock] + 2*_se[D_shock]
	mat results[`idx',6] = `h'
}

* combine with normalized changes in yields following QE1
use date DAAA using ../data/fred/_fred_raw.dta, clear
rename DAAA MD_AAA
drop if missing(MD_AAA)
sort date
forvalues h=0(`h_step')`max_h_step' {
	* long-difference relative to day before auction
	* normalize so 1-day change is 1
	gen long`h'_D_MD_AAA = (MD_AAA[_n+`h'] - MD_AAA[_n-1]) / (MD_AAA[_n] - MD_AAA[_n-1])
}
drop MD_AAA
* QE1 final announcement
keep if date==mdy(3,18,2009)
reshape long long@_D_MD_AAA, i(date) j(h)
drop date
rename long_D_MD_AAA qe1_normalized_ylds
tempfile qe1_normalized_ylds
save `qe1_normalized_ylds', replace

***************************
* plot
clear
svmat results
rename results1 b
rename results2 ci_l1
rename results3 ci_u1
rename results4 ci_l2
rename results5 ci_u2
rename results6 h

* combine with QE1 respones
merge 1:1 h using `qe1_normalized_ylds', nogen


* plot
twoway (rarea ci_l1 ci_u1 h , color(gs12) ) ///
	(line b ci_l2 ci_u2 h, lcolor("scheme p1" "scheme p1" "scheme p1") ///
		lpattern(solid shortdash shortdash ) lwidth(medium thin thin)) ///
	(line qe1_normalized_ylds h, lcolor("scheme p2") ///
		lpattern(longdash ) lwidth(thick)), ///
	xtitle("Days") ytitle("D{sub:t} Coeff.") ///
	legend(order(2 "Coefficient" 5 "Normalized QE Resp.") ring(0) position(7)) ///
	title("Panel B: Corporate Aaa Yields") ///
	name(longdiff_aaa, replace) nodraw


***************************
* combine with correct size and export
local fname f2e_longdiff_coeffs
* vertical layout
graph combine longdiff_t10 longdiff_aaa, ///
	rows(2) imargin(tiny) xsize(5) ysize(7) name(`fname', replace)
graph export ../figs/`fname'.pdf, replace
graph export ../figs/`fname'.eps, replace



